package net.xmat.webtest.dao.impl;

import java.util.List;

import net.xmat.webtest.beans.Author;
import net.xmat.webtest.dao.IAuthorDao;
import net.xmat.webtest.utils.HibernateOperations;
import net.xmat.webtest.utils.HibernateUtils;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

public class AuthorDao implements IAuthorDao {

	public Author get(Long id) {
		Session s = HibernateUtils.getSessionFactory().openSession();
		Author a = (Author)s.get(Author.class, id);
		s.close();
		return a;
	}

	public void save(final Author a) {
		new IHibernateWork() {
			public void doInTransaction(Session session) {
				session.saveOrUpdate(a);
			}
		};
	}

	public List<Author> list(String name) {
		return HibernateOperations.list(Author.class, name);
	}

}
